import { GOODSLIST ,ADDGOODSTOCART} from "../action-types/cartTypes";
const List = [{
    name:'耳机',
    price:1299,
    number:50,
    id:1
},{
    name:'手表',
    price:3299,
    number:80,
    id:2
}]
export const  goodsReducers =(state=List,action)=>{
    switch (action.type) {
        case GOODSLIST:
            return state
            break;
        case ADDGOODSTOCART:
            return getGoodsListFunc(state,action.goodsId)
            break;
        default:
            return state
            break;
    }
}
const getGoodsListFunc=(state,id)=>{
    let neWState=[]
    if(state.length>0){
        state.map(item=>{
            if(item.id == id){
                item.number = item.number -1
            }
            neWState.push(item)
        })
    }
    return neWState
}